import {connect} from "react-redux";
import { addSpaces, addReserveOrder } from "../actions/home";
import ReserveStall from "../components/ReserveStall/ReserveStall";
import {getAllSpacesByParklotId} from "../apis/parkingSpaceApi";
import {createReserveOrder} from "../apis/reserveOrderApi";

const mapStateToProps = (state) => ({
    spaces: state.spaceReducer
});
const mapDispatchToProps = (dispacth) => ({
    getAllSpacesByParklotId: async (id, time) => {
        const data = await getAllSpacesByParklotId(id, time);
        dispacth(addSpaces(data.parkingSpaceStatus));
    },
    createReserveOrder: async data => {
        const order = await createReserveOrder(data);
        dispacth(addReserveOrder(order));
    },
    updateSpaces: (data) => {
        dispacth(addSpaces(data));
    }
});
const ReserveContainer = connect(mapStateToProps, mapDispatchToProps)(ReserveStall);

export default ReserveContainer;